﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

namespace MvcStudy.Models
{
    public class HtmlHelper
    {
        /// <summary>  
        /// 压缩html代码  
        /// </summary>  
        /// <param name="text">The text.</param>  
        /// <returns></returns>  
        public static string Compress(string text)
        {
            text = Regex.Replace(text, @"<!--\S*?-->", string.Empty);
            text = Regex.Replace(text, @"^\s+|\s+{1}", string.Empty);
            text = Regex.Replace(text, "\n", " ");
            text = Regex.Replace(text, @">\s+?<", "><");
            text = Regex.Replace(text, @"\s{2,}", " ");
            text = Regex.Replace(text, " {2,}", @"\s");
            text = Regex.Replace(text, @"\s{2,}", @"\s");

            return text;
        }
    }
}